#!/bin/bash

# SrcF="/etc/apt/sources.list"
SrcF="/etc/apt/sources.list"
SrcP="/etc/apt/"
# ver=$(cat /etc/issue|awk '{print $2}'|awk -F. '{print $1}')# get major version number
ver=$(cat /etc/issue|awk '{print $2}')
# make soft link of desktop to ~
# ln -sr /mnt/c/Users/$(ls /mnt/c/Users/ |awk '{if(/Public/)next;if(/Default/)next;if(/.ini/)next;if(/All/)next;print -zsh}')/Desktop ~/desktop #some risks
# or get the User name by para

echo -n "确认Windows用户是否存在于C:/Users路径下或者需要到桌面的快捷方式 输入[y]来确认 : "
read linkNeed
linkNeed=$(echo $linkNeed|tr 'A-Z' 'a-z')
if [[ "$ans" =~ y(es)?  ]];then
declare User;
    if [ ! -e ~/desktop ];then 
        if [ -z $1 ];then    
            echo -e "\033[35mPlease input user name to make the link to your desktop\033[0m"
            echo -n "请输入用户名 : "
            read User
        else User=$1;
        fi
        if [ -e /mnt/c/Users/$User/Desktop ];then
                sudo ln -sr /mnt/c/Users/$User/Desktop ~/desktop
        else echo "No Link For You due to the wrong path"
        fi
    fi
fi

# change source list
if [ ! -e $SrcF.bak  ]
then
    if [ -e $SrcF ]
    then
        mv $SrcF $SrcF.bak
    else
        touch $SrcF
    fi
fi
# get new souces.list
#    sudo mv ~/desktop/sources.list $SrcP

# or simply use echo to add content
cp /etc/apt/sources.list ~/sources.list
sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' ~/sources.list
echo ~/sources.list|sudo tee -a /etc/apt/sources.list >/dev/null
rm ~/sources.list

if [ $? -eq 0 ]
then
#update
    sudo apt-get update
    if [ $? -eq 0 ];then
    echo -e '\033[32msources.list has been changed!\033[0m'
    fi
# install tools
    sudo apt-get install vim build-essential g++ git gdb -y
    if [ $? -eq 0 ]
    then
        echo -e "\033[33m installation done \033[0m"
    else
        echo -e "\033[31m installation ERROR \033[0m"
    fi
else
    echo -e "\033[35m update error \033[0m"
fi